/**
 * major.jsp页面
 */
 function getHeadTd(name) {
  return '<td class="head"><span>' + name + '</span></td>';
 }

 function getHead(headArray) {
  var tr = "<tr>";
  $.each(headArray, function (index, item) {
   tr += getHeadTd(item);
  });
  tr += "</tr>";
  return tr;
 }

 function getValueTd(value) {
  return '<td>' + value + '</td>';
 }

 function getValueTr(valueArray) {
  var tr = "<tr>";
  $.each(valueArray, function (index, item) {
   // debugs("item[index]:"+item);
   // debugs(index+"item[index]:"+item[index]);
   tr += getValueTd(item);
  });
  tr += "</tr>";
  return tr;
 }

 function filtUndef(value) {
  if (typeof(value) == "undefined") {
   return "";
  }
  return value;
 }

 function getYmdTime(value) {
  return getTimeYMDStr(value);
 }

 function mod(id) {
  window.location.href = "api/majors/edit/" + id
 }

 function thaw(id, status) {
  if (0 != status) {
   alertOk("<fmt:message key='no.sealed'/>！");
   return false;
  }
  if (window.confirm('<fmt:message key="sure.remove.sealed"/>？')) {
   window.location.href = "admin/member/seal?ids=" + id + "&thaw=" + 1;
  } else {
   return false;
  }

 }
 function rowResetUser(ids) {
  window.location = 'admin/member/view?ids=' + ids;
 }

 function del(id) {
   var setIds = [];
   setIds.push(id);
   layer.confirm('确定要删除该条数据？', {
      btn: ['确定', '取消']
    , btn2: function (index, layero) {
       layer.close(index);
    }, title: ['删除提示', true]
   }, function (index, layero) {
      rowDelete(setIds);
   });
  }

 function rowDelete(id) {
  $.ajax({
   url: "api/majors/remove",
   type: 'POST',
   contentType: "application/json",
   dataType: 'json',
   data: JSON.stringify({"ids": id}),
   success: function (data) {
    if (data != null && data.flag) {
      layer.alert(
          '删除成功', 
          {
              icon: 1,
              skin: 'layer-ext-moon',
              closeBtn: 0
          },
          function(){
              $('#listForm').submit();
          }
      );
    } else {
     alertError('删除失败');
    }
   }
  });
 }

  function convertLevel(params) {
    var level = params;
    var result = "";
    if (level == 1) {
      result = "本科";
    } else if (level == 2) {
      result = "专科";
    } else {
      result = "--";
    }
    return result;
  }

  /**
   * 获取学科
   * @returns
   */
  function getMajorSubject() {
    // 默认按id排序
    var query = {};
    // 学科的父级代码默认为"00"
    query.parentCode = "00";
    var searchJsonUrl = 'api/major-types/findAll';
    var param = JSON.stringify(query);

    $.ajax({
     url: searchJsonUrl,
     data: param,
     type: 'POST',
     contentType: "application/json",
     dataType: 'json',
     success: function (result) {
       debugs(result);
       var list = result.list;
       if (list.length > 0) {
         var option = "<option value=''>全部</option>";
         $.each(list, function(index, item) {
           option += "<option code='" + item.majorTypeCode + "' value='" + item.majorTypeName + "'>" + item.majorTypeName + "</option>";
         });
         $("#majorSubject").html(option);
       }
     }, 
     error: function (xhr) {
       alertError("系统异常，请联系管理员！");// 请求失败遇到异常触发
     }
    });
  }
  
  /**
   * 获取专业类
   * @returns
   */
  function getMajorClass() {
    var parentCode = $('#majorSubject option:selected').attr("code");
    debugs(parentCode);
    
    // 默认按id排序
    var query = {};
    query.parentCode = parentCode;
    var searchJsonUrl = 'api/major-types/findAll';
    var param = JSON.stringify(query);

    $.ajax({
     url: searchJsonUrl,
     data: param,
     type: 'POST',
     contentType: "application/json",
     dataType: 'json',
     success: function (result) {
       debugs(result);
       var list = result.list;
       if (list.length > 0) {
         var option = "<option value=''>全部</option>";
         $.each(list, function(index, item) {
           option += "<option code='" + item.majorTypeCode + "' value='" + item.majorTypeName + "'>" + item.majorTypeName + "</option>";
         });
         $("#majorClass").html(option);
       }
     }, 
     error: function (xhr) {
       alertError("系统异常，请联系管理员！");// 请求失败遇到异常触发
     }
    });
  }